//
//  ViewController.m
//  CollectCrashDemo
//
//  Created by Hello Cai on 2020/11/22.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self setView];
}

-(void)setView {
    
    CGFloat marginY = 60;
    CGFloat height = 40;
    CGFloat width = 160;
    CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
    NSArray *titles = @[@"数组越界"];
    for (int i = 0; i < titles.count; i++) {
        UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake((screenWidth-width)/2, 150+(marginY+height)*i, width, height)];
        [btn setTitle:titles[i] forState:UIControlStateNormal];
        [btn setBackgroundColor:[UIColor yellowColor]];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:13];
        [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        btn.tag = 1000+i;
        [self.view addSubview:btn];
    }
}

-(void)btnClick:(UIButton *)button{
    int index = (int)button.tag - 1000;
    NSLog(@"%d", index);
    if (index == 0) {
        //数组越界
        NSArray *array = @[@"haha"];
        NSLog(@"%@", array[1]);
    }
}

@end
